<template>
  <div class="password-box">
    <div class="title-div">请输入新密码</div>
    <div>
      <input type="password" v-model="password" />
    </div>
    <div class="title-div">确认密码</div>
    <div>
      <input type="password" v-model="password1" />
    </div>

    <div>
      <button @click="changePwd">完成</button>
    </div>
  </div>
</template>

<script>
import { updateUser,updatePassWithOutUser } from "api/User";
export default {
  name: "setPwdSpeed_2",
  data() {
    return {
      password: "",
      password1: "",
      phone:""
    };
  },
  mounted() {
    console.log(this.$route.query.reg,this.$route.query.phone);
    const isOk = this.$route.query.reg;
    this.phone = this.$route.query.phone;
    if (isOk != "true") {
      this.$router.go(-1);
    }
  },
  methods: {
    changePwd() {
      let newPass = this.password;
      let {password, password1,phone } = this;
      if (!password || !password1) {
        this.$toast("密码不能为空");
        return false;
      }

      if (password != password1) {
        this.$toast("两次密码不一致");
        return false;
      }
      // let params = {
      //   newPass:this.password,
      //   phone:this.phone
      // }
      console.log({newPass,phone})
      updatePassWithOutUser({newPass,phone}).then(({ data, code, message }) => {
        if (!code) {
          this.$toast("密码修改成功，请重新登录！");
          localStorage.removeItem("token");
          localStorage.removeItem("isLogin");
          localStorage.removeItem("openId");
          localStorage.removeItem("userInfo")
          setTimeout(() => window.location.href= window.location.protocol + "//" + window.location.hostname + "/h5/#/login", 500)
        } else {
          this.$toast(message);
        }
      });
    },
  },
};
</script>

<style lang="stylus" scoped>
@import './../../assets/styl/mixin.styl'
.password-box
  padding rem(16) rem(15)
  .password-title
    font-size rem(12)
    color #999999
  .title-div
    margin-top rem(20)
    margin-bottom rem(8)
    color #666666
  div
    input
      border rem(1) solid #CCCCCC
      height rem(40)
      width rem(345)
      border-radius rem(5)
      color #333333
    button
      border-radius rem(5)
      margin-top rem(54)
      width rem(345)
      height rem(49)
      background $baseColor
      color $infoColor
  .used-box
    position relative
    input
      width rem(270)
      padding-right rem(75)
    span
      position absolute
      right rem(5)
      top 40%
</style>